﻿//非空验证
function valid_isempty(field, alerttxt) {
    var strVal = document.getElementById(field).value;
    if (strVal == null || Trim(strVal) == "" || Trim(strVal) == "0") {
        //document.getElementById(field).focus();
        return alerttxt + '不可为空！\n';
    }
    else { return ""; }

}
//非空验证 select 控件
function valid_isempty_select(field, alerttxt) {
    var strVal = $("#" + field + "").val();
    if (strVal == null || Trim(strVal) == "" || Trim(strVal) == "0") {
        return "请选择" + alerttxt + '！\n';
    }
    else { return ""; }

}
//输入内容必须为非中文
function valid_isnoCh(field, alerttxt) {
    var strVal = document.getElementById(field).value;
    if (Trim(strVal).length != 0) {
           reg = /^[a-zA-Z0-9_]+$/;
//         reg = /^[a-zA-Z]{1}[a-zA-Z0-9-]{0,29}\d$/;
        if (!reg.test(Trim(strVal))) {
            document.getElementById(field).focus();
            return alerttxt + '必须为字母或数字！\n';
        }
        else
            return "";
    }
    else
        return "";
}
//判断输入的字符是否为中文    
function valid_IsChinese(field, alerttxt) {
    var strVal = Trim(document.getElementById(field).value);
    if (strVal.length != 0) {
        reg = /^[\u0391-\uFFE5]+$/;
        if (!reg.test(strVal)) {
            document.getElementById(field).focus();
            return alerttxt + '必须为中文！\n';
        }
        else {
            return "";
        }
    }
    else
        return "";
}
//判断输入的数字必须在某个特点的范围内   
function valid_MinMax(field, alerttxt, minNum, maxNum) {
    var strVal = document.getElementById(field).value;
    if (Trim(strVal).length != 0) {
        reg = /^[-+]?\d*$/;
        if (!reg.test(Trim(strVal))) {//判断是否为数字类型
            if (strVal >= minNum && strVal <= maxNum) {
                return "";  //验证通过
            }
            else {
                document.getElementById(field).focus();
                return alerttxt + '超出范围！';
            }
        }
        else {
            document.getElementById(field).focus();
            return alerttxt + '必须为数字！';
        }
    }
}

//判断输入的字符是否为整数    
function valid_IsInteger(field, alerttxt) {
    var strVal = document.getElementById(field).value;
    strVal = Trim(strVal);
    if (strVal != "" && strVal.length != 0) {
        reg = /^[-+]?\d*$/;
        if (!reg.test(strVal)) {
            document.getElementById(field).focus();
            return alerttxt + '输入格式不正确！\n';
        }
        else
            return "";
    }
}

//输入内容必须为金额格式
function valid_IsMoney(field, alerttxt) {
    var strVal = document.getElementById(field).value;
    if (Trim(strVal).length != 0) {
        reg = /^(([1-9]\d{0,9})|0)(\.\d{1,2})?$/;
        if (!reg.test(Trim(strVal))) {
            document.getElementById(field).focus();
            return alerttxt + '必须为金额格式！\n';
        }
        else
            return "";
    }
    else
        return "";
}

//去掉字符串前后空格
function Trim(str) {
    return str.replace(/(^\s*)|(\s*$)/g, "");
}

//rpt编辑信息
function EditchkChoose(menuid) {
    var cId = document.getElementById("hdf_Id").value.split(',')[0];
    document.getElementById("hdf_Id").value = "";
    if (Trim(cId) != "") {
        window.location.href = "AddEdit.aspx?type=edit&id=" + cId + "&mid=" + menuid;
        return true;
    }
    else {
        alert("请选择您要编辑的信息!");
        return false;
    }
}
//rpt审批信息
function AppchkChoose(mname, menuid) {
    var cId = document.getElementById("hdf_Id").value.split(',')[0];
    // alert("rpt审批信息ID：" + cId);
    //document.getElementById("hdf_Id").value = "";
    if (Trim(cId) != "") {
        $.tipsWindow({
            ___title: mname + "-审批",
            ___content: "url:get?../../../Controls/AppInfo.aspx?mid=" + menuid + "&InfoId=" + cId,
            ___width: "600",
            ___height: "310",
            ___drag: "___boxTitle",
            ___showbg: true
        });
    }
    else {
        alert("请选择您要审批的信息!");
        return false;
    }
}
//rpt审批信息
function AppchkDetail(mname, cId) {
    var a = $.tipsWindow({
        ___title: mname + "-审批",
        ___content: "url:get?../../../Controls/AppInfo.aspx?InfoId=" + cId,
        ___width: "600",
        ___height: "310",
        ___drag: "___boxTitle",
        ___showbg: true
    });
    if (a == 2)
        alert(a);
}
//rpt查看详细信息
function DetailchkChoose(menuid) {
    var cId = document.getElementById("hdf_Id").value.split(',')[0];
    document.getElementById("hdf_Id").value = "";
    if (Trim(cId) != "") {
        window.location.href = "Detail.aspx?type=detail&id=" + cId + "&mid=" + menuid;
        return true;
    }
    else {
        alert("请选择您要查看的信息!");
        return false;
    }
}
//rpt页面删除判断
function DeletechkChoose() {
    var cId = document.getElementById("hdf_Id").value;
    if (Trim(cId) == "") {
        alert("请选择您要删除的信息!");
        return false;
    }
    else {
        if (Trim(cId).split(',').length == 2) {
            if (Trim(cId).split(',')[1] != "0" && Trim(cId).split(',')[1] != "3") {
                alert("该数据已提交无法删除！");
                return false;
            }
        }
        if (confirm("确认删除当前选中的数据吗?") == true) {
            document.getElementById("hdfDelete").value = dId;
            return true;
        }
        else {
            return false;
        }
    }
}
//rpt页面打开数据导出窗口
function openExportWin() {
    if (typeof (qsql) != "undefined") {
        window.open("../../Export/DataExport.aspx?s=" + qsql, "_blank", "fullscreen=2,resizable=1");
    }
    return false;
}
//限制文本框只能输入数字，不包括小数点
function onlyNum() {
    if (!(event.keyCode == 46) && !(event.keyCode == 8) && !(event.keyCode == 37) && !(event.keyCode == 39))
        if (!((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105)))
            event.returnValue = false;  
}

//限制文本框只能输入数字，字母或者包含“-”
function onlyNumCode() {
    if (!(event.keyCode == 46) && !(event.keyCode == 8) && !(event.keyCode == 37) && !(event.keyCode == 39) && !(event.keyCode == 109) && !(event.keyCode == 189))
        if (!((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105) || (event.keyCode >= 65 && event.keyCode <= 90)))
            event.returnValue = false;
}

//限制文本框只能输入数字和“.”
function onlyPrice() {
//    obj.value = obj.value.replace(/[^\d.]/g, "");  //清除“数字”和“.”以外的字符
//    obj.value = obj.value.replace(/^\./g, "");  //验证第一个字符是数字而不是.
//    obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的.
//    obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
    if (!(event.keyCode == 46) && !(event.keyCode == 8) && !(event.keyCode == 37) && !(event.keyCode == 190) && !(event.keyCode == 110))
        if (!((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105)))
            event.returnValue = false;
}
function onlyMisCard(obj) {
    obj.value = obj.value.replace(/[^\d,]/g, "");  //清除“数字”和“.”以外的字符
}
/********
接收地址栏参数
key:参数名称
**********/
function GetQuery(key) {
    var search = location.search.slice(1); //得到get方式提交的查询字符串
    var arr = search.split("&");
    for (var i = 0; i < arr.length; i++) {
        var ar = arr[i].split("=");
        if (ar[0] == key) {
            return ar[1];
        }
    }
    return "";
}
//根据开始卡号和结束卡号获取 应有数量|实际数量|缺卡卡号
function GetInfoByDB(startNO, endNO, rkId,zkId) {
    var retStr = "";
    if (Trim(startNO).length == 8 && Trim(endNO).length == 8) {
        $.ajax(
            {
                type: 'get', //页面的提交方式
                url: '../../../Controls/HdMisCard.ashx', //一般处理文件的路径
                data: 'startNO=' + startNO + "&endNO=" + endNO + "&rkId=" + rkId + "&zkId=" + zkId, //传入的参数(入库单ID，盒号)
                dataType: 'html',
                cache: false,
                async: false,
                success: function (content) {
                    retStr = content;
                }
            });
    }
    return retStr;
}

//根据input的name 获取所有input相加的和
function GetSumByName(inputName) {
    var tmpName = $("input[name=" + inputName + "]");
    var tmpSum = 0;
    for (var i = 0; i < tmpName.length; i++) {
        tmpSum += parseInt(tmpName[i].value);
    }
    return tmpSum;
}

//设置input只读属性 多个用逗号隔开
function SetInputRedonley(strInput) {
    var tmp = strInput.split(',');
    for (var i = 0; i < tmp.length; i++) {
        if (tmp != "") {
            var tmpName = $("input[name=" + tmp[i].split('|')[0] + "]");
            for (var j = 0; j < tmpName.length; j++) {
                tmpName[j].setAttribute("readOnly", 'true');
                if (tmp[i].split('|').length > 1) {
                    tmpName[j].setAttribute("style", 'background-color:#eeefe1;' + tmp[i].split('|')[1]);
                }
                else
                    tmpName[j].setAttribute("style", 'background-color:#eeefe1;');
            }
        }
    }
}


// 质朴长存法实现卡号补0操作
function Pad(num, n) {
    var len = num.toString().length;
    while (len < n) {
        num = "0" + num;
        len++;
    }
    return num;
}

//获取URL参数的值
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
}